﻿namespace HuaWei
{
    using DevExpress.XtraBars;
    using DevExpress.XtraEditors;
    using DevExpress.XtraTab;
    using HuaWei.CBR;
    using HuaWei.CommClass;
    using HuaWei.CommComp;
    using HuaWei.Common;
    using HuaWei.EI;
    using HuaWei.Search;
    using HuaWei.Windows.Forms;
    using HuaWei.YZ;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class FrmSPGL : Form
    {
        private Bar bar;
        private BarDockControl barDockControl;
        private BarDockControl barDockControl1;
        private BarDockControl barDockControl2;
        private BarDockControl barDockControl3;
        private BarLargeButtonItem barLargeButtonItem2;
        private BarManager barManager;
        private SimpleButton btnCancel;
        private BarLargeButtonItem btnClose;
        private BarLargeButtonItem btnClose1;
        private SimpleButton btnExport;
        private BarLargeButtonItem btnJLSP;
        private IContainer icontainer = null;
        private ImageList imageList;
        private PanelControl panelControl6;
        private SimpleButton simpleButton1;
        private SimpleButton simpleButton2;
        private SimpleButton simpleButton3;
        private XtraTabControl xtraTabControl1;
        private XtraTabControl xtraTabControl2;
        private XtraTabPage xtraTabPage1;
        private XtraTabPage xtraTabPage2;
        private XtraTabPage xtraTabPage3;

        public FrmSPGL()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// 数据撤回
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.method3(0x61);
            if (Class28.ValidateQCInfo(this.xtraTabControl1, EOPLX.CANCEL) && Class38.smethod1("CancelUpdate", null, GParams.LoginId, GParams._BDID, GParams.QCInfo.QCID, ""))
            {
                Class28.smethod4(DBHelp.IniIDA(), this.xtraTabControl1, -1);
                this.method3(0x63);

                //撤回之后重新取一遍数据（不然数据的状态可能不对，导致导出时异常）
                method2();
            }
        }

        private void btnExport_Click(object sender, EventArgs e)
        {
            this.method3(0x61);
            if (GParams.DZYZ)
            {
                if (Class28.ValidateQCInfo(this.xtraTabControl1, EOPLX.COMFIRM) && Class37.smethod1().imethod_2())
                {
                    Class28.smethod4(DBHelp.IniIDA(), this.xtraTabControl1, 1);
                    this.method3(0x63);
                }
            }
            else if (Class28.ValidateQCInfo(this.xtraTabControl1, EOPLX.UPLOAD) && Class37.smethod1().imethod_1())
            {
                Class28.smethod4(DBHelp.IniIDA(), this.xtraTabControl1, 0);
                this.method3(0x63);
            }
        }

        public void ControlFormStatus()
        {
            Class28.SetTabPageTitle(this.xtraTabControl1.SelectedTabPage);
        }

        protected override void DefWndProc(ref Message m)
        {
            this.method3(m.Msg);
            base.DefWndProc(ref m);
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.icontainer != null))
            {
                this.icontainer.Dispose();
            }
            base.Dispose(disposing);
        }

        private void FrmSPGL_FormClosed(object sender, FormClosedEventArgs e)
        {
        }

        private void FrmSPGL_FormClosing(object sender, FormClosingEventArgs e)
        {
            DevCCHelp.CloseTabControl(this.xtraTabControl2);
        }

        private void FrmSPGL_Load(object sender, EventArgs e)
        {
            this.method1();
            this.xtraTabControl2.SelectedTabPageIndex = 0;
        }

        private void InitializeComponent()
        {
            this.icontainer = new Container();
            ComponentResourceManager resources = new ComponentResourceManager(typeof(FrmSPGL));
            this.imageList = new ImageList(this.icontainer);
            this.barManager = new BarManager(this.icontainer);
            this.bar = new Bar();
            this.barDockControl3 = new BarDockControl();
            this.barDockControl2 = new BarDockControl();
            this.barDockControl = new BarDockControl();
            this.barDockControl1 = new BarDockControl();
            this.btnJLSP = new BarLargeButtonItem();
            this.barLargeButtonItem2 = new BarLargeButtonItem();
            this.btnClose1 = new BarLargeButtonItem();
            this.btnClose = new BarLargeButtonItem();
            this.panelControl6 = new PanelControl();
            this.xtraTabControl1 = new XtraTabControl();
            this.simpleButton2 = new SimpleButton();
            this.simpleButton1 = new SimpleButton();
            this.btnExport = new SimpleButton();
            this.simpleButton3 = new SimpleButton();
            this.btnCancel = new SimpleButton();
            this.xtraTabControl2 = new XtraTabControl();
            this.xtraTabPage3 = new XtraTabPage();
            this.xtraTabPage1 = new XtraTabPage();
            this.xtraTabPage2 = new XtraTabPage();
            this.barManager.BeginInit();
            this.panelControl6.BeginInit();
            this.panelControl6.SuspendLayout();
            this.xtraTabControl1.BeginInit();
            this.xtraTabControl2.BeginInit();
            this.xtraTabControl2.SuspendLayout();
            base.SuspendLayout();
            this.imageList.ImageStream = (ImageListStreamer)resources.GetObject("imageList2.ImageStream");
            this.imageList.TransparentColor = Color.Magenta;
            //this.imageList.Images.SetKeyName(0, "");
            //this.imageList.Images.SetKeyName(1, "");
            //this.imageList.Images.SetKeyName(2, "");
            //this.imageList.Images.SetKeyName(3, "");
            //this.imageList.Images.SetKeyName(4, "");
            //this.imageList.Images.SetKeyName(5, "");
            //this.imageList.Images.SetKeyName(6, "");
            //this.imageList.Images.SetKeyName(7, "");
            //this.imageList.Images.SetKeyName(8, "");
            //this.imageList.Images.SetKeyName(9, "link.ico");
            this.barManager.Bars.AddRange(new Bar[] { this.bar });
            this.barManager.DockControls.Add(this.barDockControl3);
            this.barManager.DockControls.Add(this.barDockControl2);
            this.barManager.DockControls.Add(this.barDockControl);
            this.barManager.DockControls.Add(this.barDockControl1);
            this.barManager.Form = this;
            this.barManager.Items.AddRange(new BarItem[] { this.btnJLSP, this.barLargeButtonItem2, this.btnClose1, this.btnClose });
            this.barManager.LargeImages = this.imageList;
            this.barManager.MaxItemId = 9;
            this.barManager.StatusBar = this.bar;
            this.bar.BarName = "Status bar";
            this.bar.CanDockStyle = BarCanDockStyle.Bottom;
            this.bar.DockCol = 0;
            this.bar.DockRow = 0;
            this.bar.DockStyle = BarDockStyle.Bottom;
            this.bar.OptionsBar.AllowQuickCustomization = false;
            this.bar.OptionsBar.DrawDragBorder = false;
            this.bar.OptionsBar.UseWholeRow = true;
            this.bar.Text = "Status bar";
            this.barDockControl3.Dock = DockStyle.Top;
            this.barDockControl3.Location = new Point(0, 0);
            this.barDockControl3.Size = new Size(0x2b4, 0);
            this.barDockControl2.Dock = DockStyle.Bottom;
            this.barDockControl2.Location = new Point(0, 0x1eb);
            this.barDockControl2.Size = new Size(0x2b4, 0x16);
            this.barDockControl.Dock = DockStyle.Left;
            this.barDockControl.Location = new Point(0, 0);
            this.barDockControl.Size = new Size(0, 0x1eb);
            this.barDockControl1.Dock = DockStyle.Right;
            this.barDockControl1.Location = new Point(0x2b4, 0);
            this.barDockControl1.Size = new Size(0, 0x1eb);
            this.btnJLSP.Id = 5;
            this.btnJLSP.Name = "btnJLSP";
            this.barLargeButtonItem2.Id = 6;
            this.barLargeButtonItem2.Name = "barLargeButtonItem2";
            this.btnClose1.Id = 7;
            this.btnClose1.Name = "btnClose1";
            this.btnClose.Id = 8;
            this.btnClose.Name = "btnClose";
            this.panelControl6.Controls.Add(this.xtraTabControl1);
            this.panelControl6.Controls.Add(this.simpleButton2);
            this.panelControl6.Controls.Add(this.simpleButton1);
            this.panelControl6.Controls.Add(this.btnExport);
            this.panelControl6.Controls.Add(this.simpleButton3);
            this.panelControl6.Controls.Add(this.btnCancel);
            this.panelControl6.Dock = DockStyle.Top;
            this.panelControl6.Location = new Point(0, 0);
            this.panelControl6.Name = "panelControl6";
            this.panelControl6.Size = new Size(0x2b4, 30);
            this.panelControl6.TabIndex = 0x10;
            this.xtraTabControl1.AllowDrop = true;
            this.xtraTabControl1.Dock = DockStyle.Fill;
            this.xtraTabControl1.Location = new Point(2, 2);
            this.xtraTabControl1.Name = "xtraTabControl1";
            this.xtraTabControl1.Size = new Size(0x17d, 0x1a);
            this.xtraTabControl1.TabIndex = 12;
            this.xtraTabControl1.SelectedPageChanged += new TabPageChangedEventHandler(this.xtraTabControl1_SelectedPageChanged);
            this.xtraTabControl1.SelectedPageChanging += new TabPageChangingEventHandler(this.xtraTabControl2_SelectedPageChanging);
            this.simpleButton2.Dock = DockStyle.Right;
            this.simpleButton2.Location = new Point(0x17f, 2);
            this.simpleButton2.Name = "simpleButton2";
            this.simpleButton2.Size = new Size(0x3e, 0x1a);
            this.simpleButton2.TabIndex = 14;
            this.simpleButton2.Tag = "-1";
            this.simpleButton2.Text = "计量汇总";
            this.simpleButton2.Click += new EventHandler(this.simpleButton2_Click);
            this.simpleButton1.Dock = DockStyle.Right;
            this.simpleButton1.Location = new Point(0x1bd, 2);
            this.simpleButton1.Name = "simpleButton1";
            this.simpleButton1.Size = new Size(0x3e, 0x1a);
            this.simpleButton1.TabIndex = 13;
            this.simpleButton1.Tag = "-1";
            this.simpleButton1.Text = "修改期次";
            this.simpleButton1.Click += new EventHandler(this.simpleButton1_Click);
            this.btnExport.Dock = DockStyle.Right;
            this.btnExport.Location = new Point(0x1fb, 2);
            this.btnExport.Name = "btnExport";
            this.btnExport.Size = new Size(0x3e, 0x1a);
            this.btnExport.TabIndex = 6;
            this.btnExport.Tag = "-1";
            this.btnExport.Text = "数据导出";
            this.btnExport.Click += new EventHandler(this.btnExport_Click);
            this.simpleButton3.Dock = DockStyle.Right;
            this.simpleButton3.Location = new Point(0x239, 2);
            this.simpleButton3.Name = "simpleButton3";
            this.simpleButton3.Size = new Size(0x3e, 0x1a);
            this.simpleButton3.TabIndex = 15;
            this.simpleButton3.Tag = "-1";
            this.simpleButton3.Text = "数据退回";
            this.simpleButton3.Click += new EventHandler(this.simpleButton3_Click);
            this.btnCancel.Dock = DockStyle.Right;
            this.btnCancel.Location = new Point(0x277, 2);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new Size(0x3b, 0x1a);
            this.btnCancel.TabIndex = 5;
            this.btnCancel.Tag = "-1";
            this.btnCancel.Text = "数据撤回";
            this.btnCancel.Click += new EventHandler(this.btnCancel_Click);
            this.xtraTabControl2.Dock = DockStyle.Fill;
            this.xtraTabControl2.Location = new Point(0, 30);
            this.xtraTabControl2.Name = "xtraTabControl2";
            this.xtraTabControl2.SelectedTabPage = this.xtraTabPage3;
            this.xtraTabControl2.Size = new Size(0x2b4, 0x1cd);
            this.xtraTabControl2.TabIndex = 0x17;
            this.xtraTabControl2.TabPages.AddRange(new XtraTabPage[] { this.xtraTabPage1, this.xtraTabPage2, this.xtraTabPage3 });
            this.xtraTabControl2.SelectedPageChanged += new TabPageChangedEventHandler(this.xtraTabControl2_SelectedPageChanged);
            this.xtraTabControl2.SelectedPageChanging += new TabPageChangingEventHandler(this.xtraTabControl2_SelectedPageChanging);
            this.xtraTabPage3.Name = "xtraTabPage3";
            this.xtraTabPage3.Size = new Size(0x2ad, 0x1af);
            this.xtraTabPage3.Text = "其它计量";
            this.xtraTabPage1.Name = "xtraTabPage1";
            this.xtraTabPage1.Size = new Size(0x2ad, 0x1af);
            this.xtraTabPage1.Text = "中间计量";
            this.xtraTabPage2.Name = "xtraTabPage2";
            this.xtraTabPage2.PageVisible = true;
            this.xtraTabPage2.Size = new Size(0x2ad, 0x1af);
            this.xtraTabPage2.Text = "变更计量";
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            base.ClientSize = new Size(0x2b4, 0x201);
            base.Controls.Add(this.xtraTabControl2);
            base.Controls.Add(this.panelControl6);
            base.Controls.Add(this.barDockControl);
            base.Controls.Add(this.barDockControl1);
            base.Controls.Add(this.barDockControl2);
            base.Controls.Add(this.barDockControl3);
            base.Name = "FrmSPGL";
            this.Text = "审批管理";
            base.WindowState = FormWindowState.Maximized;
            base.FormClosing += new FormClosingEventHandler(this.FrmSPGL_FormClosing);
            base.FormClosed += new FormClosedEventHandler(this.FrmSPGL_FormClosed);
            base.Load += new EventHandler(this.FrmSPGL_Load);
            this.barManager.EndInit();
            this.panelControl6.EndInit();
            this.panelControl6.ResumeLayout(false);
            this.xtraTabControl1.EndInit();
            this.xtraTabControl2.EndInit();
            this.xtraTabControl2.ResumeLayout(false);
            base.ResumeLayout(false);
        }

        private void method(object sender, ItemClickEventArgs e)
        {
            CHelp.openMdiFrm(this, new FrmJLSP());
        }

        private void method1()
        {
            Class28.JvBxsoguG(this.xtraTabControl1, true);
        }

        private void method2()
        {
            XtraTabPage selectedTabPage = this.xtraTabControl2.SelectedTabPage;
            if (selectedTabPage.Controls.Count == 0)
            {
                switch (this.xtraTabControl2.SelectedTabPageIndex)
                {
                    case 0:
                        if (!selectedTabPage.HasChildren)
                        {
                            FrmJLSP frm = new FrmJLSP();
                            CHelp.ControlAddForm(selectedTabPage, frm, true);
                        }
                        break;

                    case 1:
                        if (!selectedTabPage.HasChildren)
                        {
                            int type = 0;
                            if (GParams._JGLX == JGLX.YZ)
                            {
                                type = 1;
                            }
                            FrmBGJL mbgsp = new FrmBGJL(type);
                            CHelp.ControlAddForm(selectedTabPage, mbgsp, true);
                        }
                        break;

                    case 2:
                        if (!selectedTabPage.HasChildren)
                        {
                            FrmQTJL mqtjl = new FrmQTJL();
                            CHelp.ControlAddForm(selectedTabPage, mqtjl, true);
                        }
                        break;
                }
            }
            else
            {
                this.method3(0x62);
            }
        }

        private void method3(int numD)
        {
            XtraTabPage selectedTabPage = this.xtraTabControl2.SelectedTabPage;
            if (selectedTabPage.Controls.Count > 0)
            {
                Form form = (Form)selectedTabPage.Controls[0];
                if (numD.Equals(0x63))
                {
                    this.ControlFormStatus();
                }
                else if (numD.Equals(0x62))
                {
                    this.ControlFormStatus();
                }
                else if (numD.Equals(0x60))
                {
                    numD = 0x62;
                    this.method1();
                    this.ControlFormStatus();
                }
                GParams.CXJZ = true;
                Win32API.SendMessage(form.Handle, numD, 0, 0);
            }
        }

        private void method4()
        {
            int num = 0;
            QCInfo tag = (QCInfo)this.xtraTabControl1.SelectedTabPage.Tag;
            if (this.xtraTabControl1.SelectedTabPageIndex > 1)
            {
                num = this.xtraTabControl1.SelectedTabPageIndex - 1;
                QCInfo info2 = (QCInfo)this.xtraTabControl1.TabPages[num].Tag;
                if (info2.QCZT.Equals(0))
                {
                    MsgBox.ShowMsg("本期之前存在末结束的期次！");
                    return;
                }
            }
            tag.QCZT = 1;
            this.xtraTabControl1.SelectedTabPage.Tag = tag;
            DBHelp.ExeSql("update xmqc set zt=1 where bdid='#bdid#' and qcid='#qcid#'".Replace("#bdid#", GParams._BDID).Replace("#qcid#", tag.QCID));
            this.xtraTabControl1.SelectedTabPage.Tag = tag;
            GParams.QCInfo = tag;
            this.method3(0x63);
        }

        private bool method5()
        {
            int num = 0;
            if (this.xtraTabControl1.SelectedTabPageIndex < (this.xtraTabControl1.TabPages.Count - 1))
            {
                num = this.xtraTabControl1.SelectedTabPageIndex + 1;
                QCInfo tag = (QCInfo)this.xtraTabControl1.TabPages[num].Tag;
                if (tag.QCZT.Equals(2))
                {
                    MsgBox.ShowMsg("操作错误，请先对后面的期次数据解锁！");
                    return false;
                }
            }
            return true;
        }

        private void method6(object sender, EventArgs e)
        {
            this.method4();
        }

        private void method7()
        {
            IExport export = Class37.smethod1();
            string text1 = GParams._str + "-" + GParams._BDName;
            if (export.imethod_3())
            {
                this.method3(0x63);
            }
        }

        private bool method8()
        {
            FrmAddQc qc = new FrmAddQc();
            qc.IniQC(false);
            if (qc.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                this.xtraTabControl1.SelectedTabPage.Tag = GParams.QCInfo;
                this.method3(0x63);
                return true;
            }
            return false;
        }

        private void method9(object sender, EventArgs e)
        {
            if (this.method5())
            {
                string msg = "若下达此令，则承包人对应的计量期数据均解除锁定，\r\n承包人需修改对应计量期数据后，重新将对应期数据导出，\r\n然后逐级上报审批，您确定下达此令吗?";
                if ((MsgBox.ShowQuestion(msg) == System.Windows.Forms.DialogResult.OK) && Class38.smethod1("UnLock", null, GParams.LoginId, GParams._BDID, GParams.QCInfo.QCID, ""))
                {
                    Class28.smethod4(DBHelp.IniIDA(), this.xtraTabControl1, -1);
                    this.method3(0x63);
                }
            }
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            this.method8();
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            this.method3(0x61);
            new FrmSearchJLHZ().ShowDialog();
        }

        private void simpleButton3_Click(object sender, EventArgs e)
        {
            if (Class38.RobackDataValidate() && MessageBox.Show("确定需要执行退回操作？", "退回提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                this.method3(0x61);
                if (Class38.smethod1("RobackData", null, GParams.LoginId, GParams._BDID, GParams.QCInfo.QCID, ""))
                {
                    SPGLUtils.RobackData(GParams.LoginId, GParams._BDID, GParams.QCInfo.QCID, false);
                    this.method3(0x63);
                }
            }
        }

        private void xtraTabControl1_SelectedPageChanged(object sender, TabPageChangedEventArgs e)
        {
            if ((e.Page != null) && (e.Page.Tag != null))
            {
                GParams.QCInfo = (QCInfo)e.Page.Tag;
                this.method3(0x62);
            }
        }

        private void xtraTabControl2_SelectedPageChanged(object sender, TabPageChangedEventArgs e)
        {
            this.method2();
        }

        private void xtraTabControl2_SelectedPageChanging(object sender, TabPageChangingEventArgs e)
        {
            this.method3(0x61);
        }
    }
}

